<!DOCTYPE html>
<html>
<head>
    <title>商品详情</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <script src="../public/lobster/js/public.js"></script>
    <link rel="stylesheet" type="text/css" href="../public/lobster/icon/iconfont.css">
    <link rel="stylesheet" href="../public/lobster/css/shared.css">
    <link rel="stylesheet" href="../public/lobster/icon/iconfont.css">
	<link rel="stylesheet" href="../public/lobster/css/href.css?20170421">
    <script src="../public/lobster/js/lick.js"></script>
    <script src="../public/lobster/js/click.js"></script>
    <link rel="stylesheet" href="../public/lobster/css/public.css">
    <style>
    
    	.commodity .popu .btn a {
		    width: 2.6rem;
		}
		.commodity .select-morder {
		    top: 0;
		    left: 0;
		    bottom: 0;
		    right: 0;
		    position: fixed;
		    background: rgba(0, 0, 0, 0.7);
		    display: none;
		}
    	.select-morder .selecting{
    		position: fixed;
    		top: 0;
		    left: 0;
		    bottom: 0;
		    right: 0;
    		width: 100%;
    		background: #eee;
    		
    	}
    	.selecting .pop-detail{
            width: 100%;
            position: absolute;
    		top: 0;
		    left: 0;
		    bottom: 0;
		    right: 0;
		    overflow: hidden;
        }
     		.pop-detail .aa>ul{
			    text-align: center;
			    position: absolute;
	    		top: 0;
			    left: 0;
			    bottom: 1rem;
			    right: 0;		 
			    visibility: visible;
			    overflow: auto;
			}	 
       		.pop-detail .aa>ul>li {
			    display: inline-block;
			    margin: .1rem;
			    width: 7.1rem;
			    height:2.18rem;
			    background: url(/public/lobster/images/reddb.png) no-repeat;
				background-size: 100%;
				margin-top: .2rem;
			}			
			.pop-detail .aa>ul>li .cp-left{
			    float: left;			
			    width: 2.2rem;
			    height:2.18rem;
			    line-height: 2.4rem;
			    font-size:.9rem;
			    color:#fff;
			    text-indent: .1rem;
			    vertical-align:bottom;
			}
			.pop-detail .aa>ul>li  .cp-right{
			    width: 100%;
			    height:2.18rem;
			    padding:.3rem;
			    padding-left: 2.4rem;
			    text-align: left;
			    position: relative;
			    color: #646464;
			}
			.pop-detail .aa>ul>li .icon-qian{
			    font-size: .35rem;
			}
			.pop-detail .cp-right h1{
			    font-size: .4rem;
			}
			.pop-detail .cp-right ol li{
			    list-style-type: disc;
			    text-align: left;
			    font-size: .24rem;
			    margin-left: .4rem;
			}
			.pop-detail .cp-right p{
			    font-size: .3rem;
			    padding-bottom: .1rem;
			}
			.cp-right .select-box{
				position: absolute;
				top:.78rem;
				right:.2rem;
				width: .6rem;
				height: .6rem;
				background: url(../public/lobster/images/nred.png) no-repeat;
				background-size: 100%;
			}
			.cp-right .select-box .select{
				display:inline-block;
				width: 100%;
				height:100%;
				opacity: 0;
			}
			.selecting .result{
				height: .8rem;
				width: 100%;
				position: fixed;
				bottom: 0;
				left:0;
			}
			.selecting .result ul:after{
				height: 0;
				display: block;
				content: "";
				clear: both;
			}
			.selecting .result li{
				line-height: .8rem;
				width: 50%;
				float: left;
				text-align: center;
				font-size: .36rem;
				color: #fff;
			}
			.commodity .comm-detail li .cp-price {
			    height: .6rem;
			    line-height: .6rem;
			    background: #fff;
			    font-size: .3rem;
			    color: #adadad;
			    float: left;
			    padding-right: .2rem;
			}
			.coupon p span{
				display: inline-block;
				padding: .05rem .1rem;
				line-height: 1.2em;
				border: 1px solid #ad0101;
				border-radius: 3px;
				color: #ad0101!important;
				margin-left: .2rem;
			}
			.mooned{
				position: fixed;
				top:0;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 300;
				background: rgba(0,0,0,0.6);
				display: none;
			}
			.mooned .mained{
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				width: 100%;
				margin: auto;
			}
    </style>
</head>
<body class="commodity">
    <p class="fix-head"><i class="iconfont icon-left" onclick="window.history.back()"></i> 商品详情</p>
    <div class="comm-main">
        <div class="comm-img">
            <img src="http://dqimgs.shdqdzsw.com/-f7IjrXojnfImVUQCP71o7W-.jpg" alt="">
        </div>
        <input type="hidden" id="commodity_id" value="50000194"> 
        <input type="hidden" id="commodity_status" value="-1">
        <div class="describe">
            <h2>海南黄花梨2.0X13颗佛珠手串</h2>
        </div>
        <div class="comm-detail">
            <ul>
                <li>
                
                 
                 	<p>单价：<i class="iconfont icon-qian"></i> <span class="univalent">5.0</span></p>
                 
                </li>
                <li>
	                
		            
	                    <p>运费： <span class="freight">10.0</span><span>(运费首件10.0元,此后每件依次加2.0元)</span></p>
	                    <input type="hidden" id="postageMoney" value="10.0">
	                    <input type="hidden" id="postChareMoney" value="2.0">
	                
                </li>
                <li>
                    <p>数量：</p>
                    <div class="num-detail">
						<span class="minus" id="minus-1"
							onclick="changeNum('num_1','minus-1',2.0)">-</span> <input id="num_1"
							type="number" value="0" class="num_input" max="20" onkeyup="value=value.replace(/[^\d]/g,'')" >
						<span class="add" id="add-1" onclick="changeNum('num_1','add-1',2.0)">+</span>
					</div>
                </li>
                <!-- 限定大首页商品10  和 全款全货商品 0可以使用代金券 -->
                 
            </ul>
        </div>
        <div class="comm-intr">
            <p>商品介绍</p>
            <div class="intr-img">
                
					<img src="http://dqimgs.shdqdzsw.com/DE9KLa_AmWSM7C_EejSQp_ht.jpg" alt="">
				
					<img src="http://dqimgs.shdqdzsw.com/V37XkF_RjzUmsYYGpcYBIx_y.jpg" alt="">
				
					<img src="http://dqimgs.shdqdzsw.com/gD5zrOoVw3rIxpShlw9b8iIu.jpg" alt="">
				
					<img src="http://dqimgs.shdqdzsw.com/DZ0RqlyKrR9LZ3StCbu90Qvx.jpg" alt="">
				
            </div>
        </div>
    </div>
    <div class="fix-foot">
    	
    	
	        <div class="fix-yue">账户余额：<span>15.02</span></div>	        
        
	        <!-- <div class="fix-buy iconfont icon-mangouwuche" id='lijigoumai' onclick="payForOrder(-1)"> 立即购买</div> -->
            <div class="fix-buy iconfont icon-mangouwuche" id='lijigoumai' onclick="paysucc()"> 立即购买</div>

    </div>
    <!--下单弹窗-->
    <div class="morder">
        <div class="popu">
            <div class="popu-title">
                <i class="iconfont icon-tishi"></i> 下单成功
                <b class="iconfont icon-cha"></b>
            </div>
            <input type="hidden" id="depotId"> 
            <input type="hidden" id="goodsId">
            <div class="popu-main">您需要升级商品吗？</div>
            <div class="btn">
            	
	                <a href="javascript:void(0);" class="pay" onclick="success()" style="width:1.7rem;">猜鸡藕</a>
	              	<!--   <a href="javascript:void(0);" class="tihuo" onclick="goUpsdowns()">猜涨跌</a>  -->
	                <!-- <a href="javascript:void(0);" class="tihuo" style="background-color:#0f7dc7;width:1.7rem;" onclick="gohongbao()">拆红包</a>-->
	                <a href="javascript:void(0);" class="tihuo" onclick="gohongbao()" style="width:1.7rem;">拆红包</a>
            	
                <a href="javascript:void(0);" class="tihuo" onclick="gopickup()" style="width:1.7rem;">去提货</a>
            </div>
        </div>
    </div>
    
     
    <div class="select-morder" id="morder1" >
	    <div class="selecting">
	      	<div class="pop-detail">
	      		<div class="aa">
	                <ul>
	                	
					</ul>
				</div>
				<div class="result">
					<ul>
						<li style="background: #D32831;" id="cp-quit">使用</li>
						<li style="background: #febb2c;" id="cp-cancel">取消</li>
					</ul>
				</div>
            </div>
	    </div>
	</div> 
	<div class="mooned">
		<div class="mained">
			<img src="" alt="" style="width: 100%;"/>
		</div>
	</div>
	
	<div class="href">
      	    <a href="lotteryInfo.html">
      	    	榜
      	    </a> 
        	<a href="center.html">
				<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1493966935986" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3765" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M632.855273 565.992727c101.771636-47.080727 172.590545-149.317818 172.590545-267.869091 0-163.118545-133.678545-295.842909-298.007273-295.842909C343.202909 2.280727 209.454545 135.005091 209.454545 298.077091c0 118.597818 70.842182 220.834909 172.590545 267.915636C188.020364 622.336 44.311273 805.329455 38.469818 1024l46.615273 0 844.753455 0 46.638545 0C970.612364 805.329455 826.926545 622.336 632.855273 565.992727z" p-id="3766"></path></svg>
        	</a>
        	<a href="index.html" class="iconfont icon-zhuye1"></a>
       </div>
</body>
<script src="../public/lobster/js/jq-2.1.0.js"></script>
<script src="../public/lobster/js/pinchzoom.min.js"></script>
<script src="../public/lobster/js/xxy.js"></script>
<script src="../public/lobster/js/explain.js"></script>
<script src="../public/lobster/js/xxpopup.js"></script>
<script type="text/javascript">orderInfo('');</script>
<script type="text/javascript">
    function paysucc() {
        $('.morder').show();
    }
</script>


<script>
var couponClass,cprice=0,Cprice,couponclass="";
function id(a){
	return document.getElementById(a);
}
function switchicon(obj){
	if (obj.checked == true) {
                $(obj).parent().css({"background":"url(/public/lobster/images/okey.png) no-repeat","background-size":"100%"});
            }else{
            	$(obj).parent().css({"background":"url(/public/lobster/images/nred.png) no-repeat","background-size":"100%"});
    }
}
function nocheck(obj){
	$(obj).attr("disabled", "disabled");
    $(obj).parent().parent().parent().css({"background":"url(/public/lobster/images/nreddb.png) no-repeat","background-size":"100%"});
}
function coupon(){
	var add=id("num_1").value;	
	var univalent=$(".univalent").html();

	if(add>0){
		$("#morder1").css("display","block");
		switchicon(this);
        check(add,univalent);
        cprice=0;
    	couponClass="";
		$(".select").bind('click',function(){
			switchicon(this);
            check(add,univalent);
        })
	}
	 $(".result").on("click",function(){
        $(".select").each(function () {	 
            $(this).removeAttr("checked"); 
            check(add,univalent);
            switchicon(this);
        })   
        $("#morder1").css("display","none");            	
    }) 
    $("#cp-quit").one("click",function(){
    	$(".cp-price").html("￥<span style='color:#ad0101' id='cpprice'>"+Cprice+"</span>"); 	
    	cprice=parseInt($("#cpprice").html());
    	console.log(cprice);
    	couponClass=couponclass;
            var yue=parseInt($('.fix-yue span').html());
    	    var valent=parseInt($(".univalent").html());
    	    var val=parseInt($("#num_1").val());
    	    var add=valent*val-Cprice;
    	    var one=parseInt($("#postageMoney").val());
    	 	  if(add>yue){
    	   		   	 console.log("999");    	   					
    	   		     $("#num_1").val(0);    	   					
    	   		  	 $(".freight").html(one);
    	   		 	 $(".cp-price").html("当前未使用");
    	      		 couponClass="";
    	      		 cprice=0;
    	   			 xxy.popup("提示","你的余额已不足，是否直接前往充值?","确认","取消");
    						$('#xxy-popup-done').bind('click',function(){
    							window.location.href='recharge.html';	
    				        });   			
    	   	   }
    })
    
    
    $("#cp-cancel").on("click",function(){
    	$(".cp-price").html("当前未使用");
    	couponClass="";
    })
	
}
function  check(add,univalent){
	var add=add;
    var select = $(".select");
    var len = $(".select").length;
    var num=0,total=0,cost,prices,price;
    	cost=add*univalent;
    	couponclass="";
    for(var i=0;i<len;i++){
        if(select[i].checked){
        	num+=1;
        }
    }
    if(num>=add){
         select.each(function () {
            if (this.checked == false) {
            	nocheck(this);
            }
        })   
    }else{     
        select.each(function () {      
	            if (this.checked == false) {
	                    $(this).removeAttr("disabled"); 
	                    $(this).parent().parent().parent().css({"background":"url(/public/lobster/images/reddb.png) no-repeat","background-size":"100%"});
	            }
     		})      
    }
    select.each(function () {
                    if (this.checked == true) {
                        prices=parseInt($(this).parent().parent().parent().find(".cp-left span").html());
                        couponclass+=($(this).parent().parent().parent().find(".couponclass").val()).toString()+",";
                        total=total+prices;  
                    }
    })   
    select.each(function () {
                    if (this.checked == false) {
                        price=parseInt($(this).parent().parent().parent().find(".cp-left span").html());
                        //20170603李立    修改为商品总价低于两倍优惠券的商品为无法使用状态
                        if((total+price)*2>cost){
                        	nocheck(this);
                        }
                    }
    })   
    Cprice=total;
}
	
	

   function prevent(e){
	   e.preventDefault();
   }
   
    $(function(){
    	$("#num_1").val(0);
    	$("#num_1").blur(function(){
    		 var reg=/[\d]/g;
    		if(!reg.test($(this).val())){
    			$(this).val(0);
    		}
            if(update()){
                if($(this).val()>20){
                    $(this).val(20);  
                }
                if($(this).val()<0){
                    $(this).val(0);
                }
                cfreight();
            }
        });
    
        $(".enters").focus(function(){
            $("h4").html("");
        });
        
        $(".fix-buy iconfont icon-mangouwuche").click(function() {	
        
            $(".morder").css("display","block");
            window.parent.document.body.addEventListener('touchmove',prevent,false);
            
        })
        $(".icon-cha").click(function() {
            $(".morder").css("display","none");
            window.parent.document.body.removeEventListener('touchmove',prevent,false);
          	window.location.href="/user/depot";
            
        })
        
        /* 图片放大功能 */
        
        $('.intr-img img').click(function () {
    		var height=$(this).height();
    		var width=($(this).width())/50+"rem";
    		$(".mained").css("height",width);
    		$(".pinch-zoom-container").css("height",width);
            	var src=$(this).attr("src");
            	$(".mained img").attr("src",src);
            	window.parent.document.body.addEventListener('touchmove',prevent,false);
            	$(".mooned").show();
    	});
    	$('.mooned').click(function () {
    	 	window.parent.document.body.removeEventListener('touchmove',prevent,false);
        	$(this).hide();
            
    	});
    	$('.mooned img').each(function () {
            	new RTP.PinchZoom($(this), {});
    	});  

        
        
    })

function update(){
    var cprices=parseInt(cprice);
    var yue=parseInt($('.fix-yue span').html());
    var valent=parseInt($(".univalent").html());
    var freight=parseInt($(".freight").html());
    var postageMoney=parseInt($("#postageMoney").val());
    var postChareMoney=parseInt($("#postChareMoney").val());
    var val=parseInt($("#num_1").val())+1;
    var valuing=parseInt($("#num_1").val());
    var status = $("#commodity_status").val();
    //判断人民币
    if(status == 0 || status == -1){ 
      //没有优惠券或者有优惠券没有选择的
      var total=valent*val-cprices;
      if(cprices==0){
    	 
    	  if(total>yue){
   		   console.log("11");
   			 for(var add,odd,i=0;i<=21;i++){
   	             add=valent*i-cprices;
   	             odd=valent*20;
   	             if(add>yue){
   					if(i==0){
   						$("#num_1").val(i);
   					}else{
   						$("#num_1").val(i-1);
   					}
   	                 cfreight();
   	                 break;
   	             }
   	         }
   			 xxy.popup("提示","你的余额已不足，是否直接前往充值?","确认","取消");
					$('#xxy-popup-done').bind('click',function(){
						window.location.href='recharge.html';	
			        });   			
   			 
   	         return false;
   	   } 
      }else if(cprices>0){
    	  //有使用优惠券的判断
    	  var total=valent*val-cprices; 
    	  if(total>yue){
      			 for(var add,odd,i=0;i<=21;i++){    	             
      	             add=valent*i-cprices;     	            
      	             odd=valent*20;
      	             if(add>yue){
      					if(i==0){
      						$("#num_1").val(i);
      					}else{
      						$("#num_1").val(i-1);
      					}
      	                 cfreight();
      	                 break;
      	             }
      	         }
      			 xxy.popup("提示","你的余额已不足，是否直接前往充值?","确认","取消");
   					$('#xxy-popup-done').bind('click',function(){
   						window.location.href='recharge.html';
   			        }); 	 
      	         return false;
      	   } 
      }
    	
    }else if(status == 3){
    	//判断金币
    	var total=valent*val;
        if(cprices==0){
      	  if(total>yue){
     		   console.log("11");
     			 for(var add,odd,i=0;i<=21;i++){
     	             add=valent*i;
     	             odd=valent*20;
     	             if(add>yue){
     					if(i==0){
     						$("#num_1").val(i);
     					}else{
     						$("#num_1").val(i-1);
     					}
     	                 cfreight();
     	                 break;
     	             }
     	         }
     			 xxy.popup("提示","你的金币余额已不足","确认","取消");
  					$('#xxy-popup-done').bind('click',function(){
  							
  			        });   			 
     	         return false;
     	   } 
       }
	}
    if(valuing>20){
	 	  xxone.popup("提示","最大只能购买20件!","确认"); 
	 }
  return true;
}
    
    
    
  //失去焦点改变运费
    function cfreight(){
    	var a=parseInt($("#postageMoney").val());
    	var b=parseInt($("#postChareMoney").val());
        var one=parseInt($("#num_1").val());
        if(one!="0"){
            var freight=a+(one-1)*b;
            $(".freight").html(freight);
        }else{
            $(".freight").html(a);
        }
    }


    /*改变所购商品的数量--购物车功能*/
    function changeNum(numId,flag,postChareMoney){
    	//console.log("111")
    	var freight=parseInt($(".freight").html());
        var numId=document.getElementById(numId);
        var isminus = flag.indexOf("minus")==-1?false:true;
        if(isminus){
            if(numId.value<=0){
                return false;
            } else{
            	numId.value=parseInt(numId.value)-1;
            	$(".cp-price").html("当前未使用");
            	cprice=0;
            	couponClass="";
                cfreight(freight,postChareMoney);
                if(numId.value==0){
                    $(".total span").html(0+"元");
                }
            }
        } else if(update()){
        	if(numId.value<20){
                numId.value=parseInt(numId.value)+1;
               /*  $(".cp-price").html("当前未使用");
                couponClass=""; */
                cfreight();
            }
        }else {
            return false;
        }
    }
  
   // 金币兑换 
   
  function  toChange(){
	  xxy.popup("提示","确定要兑换商品吗？","确认","取消");
	  
	  $('#xxy-popup-done').bind('click',function(){
		  
		  if(noempty('#num_1')){
				var num=$("#num_1").val();
				if(num==0){
					//alert("请选择下单数量");
					xxone.popup("提示","请选择兑换数量","确认");
					return;
				}
				if(num>5){
					//alert("此商品最多每次可以购买20个");
					xxone.popup("提示","此商品最多每次可以兑换5个","确认");
						return ;
				}
				
				var money=parseFloat($("#availMoney").html());
				 var price =parseFloat($("#price").html());
				 if(price*num>money){
					 xxy.popup("提示","你的余额已不足,兑换失败","确认","取消");
					 return;
				 }
				 
				 var  commdityId=$("#commodity_id").val();
				 
				 $.ajax({
					 type:"POST", 
					 url:"/user/changeGoods?v="+Math.random(),
					 data:{
						 "goodsId":commdityId,
						 "num":num
					 },
					 dataType:"json",
					 success:function(data){
							// 铃声 
							var audio=document.createElement("audio");
					        audio.src='/public/lobster/video/dingding.mp3';
					        audio.play();
						 if(data.success){
							  //跳转到我的订单页面
							  xxy.popup("提示","兑换商品成功!","确认","取消");
							  
							  $('#xxy-popup-done').bind('click',function(){
									 window.location.href='depot.html';
							  });
							 
						 }else{
							 xxy.popup("提示",data.msg,"确认","取消"); 
							 
						 }
					 }
				 })
		  }	 
	  });
   }

//下单
function payForOrder(status){
	 /*改版后的方法  */
    //获取到商品的状态
    //1.正常商品的状态为0
    //alert(cprices);
    if(status==0||status==10||status==4){
    	var cprices = parseInt(cprice);
    	//alert(cprices);
    	//没有使用优惠券或者没有优惠券
		if(cprices == 0){
			//alert("没有优惠券正常商品");
			//alert(couponClass);
			if(noempty('#num_1')){
				var num=$("#num_1").val();
				if(num==0){
					//alert("请选择下单数量");
					xxone.popup("提示","请选择下单数量","确认");
				
					return;
				}
				if(num>20){
					//alert("此商品最多每次可以购买20个");
					xxone.popup("提示","此商品最多每次可以购买20个","确认");
						return ;
				}
				var money=parseFloat($("#availMoney").html());
				 var price =parseFloat($("#price").html());
				if(price*num>money){
					xxy.popup("提示","你的余额已不足，是否直接前往充值?","确认","取消");
					$('#xxy-popup-done').bind('click',function(){
					
						window.reload();
						
	                 });
					return;
				}		     	
			        var  commdityId=$("#commodity_id").val();
			        var type=1;
			        //添加正常商品没有优惠券的订单
		    	$.ajax({
					  type:'POST',
					  url:"/user/addNormalOrder?v="+Math.random(),
					  data:{"num":num,"goodId":commdityId,"type":type},
					  dataType:"json",
					  success:function(data){
							// 铃声 
							var audio=document.createElement("audio");
					        audio.src='/public/lobster/video/dingding.mp3';
					        audio.play();
						if(data.success){
								setTimeout(function(){
									if(data.data.status == -1){
										$("#depotId").val(data.data.depotId);
										$("#goodsId").val(data.data.goodsId);
							            $(".morder").show();
							            window.parent.document.body.addEventListener('touchmove',prevent,false);
									}else{
										window.location.href='/user/depot';
									}
								} ,800);//延时0.5秒 
							}else{
								xxone.popup("提示",data.msg,"确认");
								 $('#xxone-popup-done').bind('click',function(){
									 window.location.href='/commodity/index';
			    				  });
								
							}
						}
				  });
				}
					
		}
    	//使用优惠券
		else if(cprices > 0){
			//alert("有优惠券正常商品");
			//alert(couponClass);
			if(noempty('#num_1')){
				var num=$("#num_1").val();
				if(num==0){
					xxone.popup("提示","请选择下单数量","确认");
				
					return;
				}
				if(num>20){
					xxone.popup("提示","此商品最多每次可以购买20个","确认");
						return ;
				}
				var money=parseFloat($("#availMoney").html());
				 var price =parseFloat($("#price").html());
				if(price*num>money){
					xxy.popup("提示","你的余额已不足，是否直接前往充值?","确认","取消");
					$('#xxy-popup-done').bind('click',function(){
						window.location.href='recharge.html';
						
	                 });
					return;
				}		     	
			        var  commdityId=$("#commodity_id").val();
			        var type=1;
			        //添加正常商品有优惠券的订单
		    	$.ajax({
					  type:'POST',
					  url:"/user/addNormalCouponOrder?v="+Math.random(),
					  data:{"num":num,"goodId":commdityId,"type":type,"couponids":couponClass},
					  dataType:"json",
					  success:function(data){
							// 铃声 
							var audio=document.createElement("audio");
					        audio.src='/public/lobster/video/dingding.mp3';
					        audio.play();
						if(data.success){
								setTimeout(function(){
									if(data.data.status == -1){
										$("#depotId").val(data.data.depotId);
										$("#goodsId").val(data.data.goodsId);
							            $(".morder").show();
							            window.parent.document.body.addEventListener('touchmove',prevent,false);
									}else{
										window.location.href='/user/depot';
									}
								} ,800);//延时0.5秒 
							}else{								
								xxone.popup("提示",data.msg,"确认");
								 $('#xxone-popup-done').bind('click',function(){
									 window.location.href='/user/recharge';
			    				  });
								
							}
						}
				  });
				}
		}
    }
	//2.升级商品的状态为-1
    else if(status==-1){
    	//alert("升级商品");
    	if(noempty('#num_1')){
				var num=$("#num_1").val();
				if(num==0){
					xxone.popup("提示","请选择下单数量","确认");
				
					return;
				}
				if(num>20){
					xxone.popup("提示","此商品最多每次可以购买20个","确认");
						return ;
				}
				var money=parseFloat($("#availMoney").html());
				 var price =parseFloat($("#price").html());
				if(price*num>money){
					xxy.popup("提示","你的余额已不足，是否直接前往充值?","确认","取消");
					$('#xxy-popup-done').bind('click',function(){
						window.location.href='recharge.html';
						
	                 });
					return;
				}		     	
			        var  commdityId=$("#commodity_id").val();
			        var type=1;
			        //添加升级商品订单
		    	$.ajax({
					  type:'POST',
					  url:"/user/addOrder?v="+Math.random(),
					  data:{"num":num,"goodId":commdityId,"type":type},
					  dataType:"json",
					  success:function(data){
							// 铃声 
							var audio=document.createElement("audio");
					        audio.src='/public/lobster/video/dingding.mp3';
					        audio.play();
						if(data.success){
								if(data.data.status == -1){
									$("#depotId").val(data.data.depotId);
									$("#goodsId").val(data.data.goodsId);
						            $(".morder").show();
						            window.parent.document.body.addEventListener('touchmove',prevent,false);
								}else{
									window.location.href='/user/depot';
								}
							}else{
								xxone.popup("提示",data.msg,"确认");
								 $('#xxone-popup-done').bind('click',function(){
									 window.location.href='/user/recharge';
			    				  });
								
							}
						}
				  });
				}
    }
	//3.金币商品的状态为3
    else if(status==3){
    	//alert("金币商品");
    	xxy.popup("提示","确定要兑换商品吗？","确认","取消");
  	  
	  	  $('#xxy-popup-done').bind('click',function(){
	  		  
	  		  if(noempty('#num_1')){
	  				var num=$("#num_1").val();
	  				if(num==0){
	  					xxone.popup("提示","请选择兑换数量","确认");
	  					return;
	  				}
	  				if(num>5){
	  					xxone.popup("提示","此商品最多每次可以兑换5个","确认");
	  						return ;
	  				}
	  				
	  				var money=parseFloat($("#availMoney").html());
	  				 var price =parseFloat($("#price").html());
	  				 if(price*num>money){
	  					 xxy.popup("提示","你的余额已不足,兑换失败","确认","取消");
	  					 return;
	  				 }
	  				 
	  				 var  commdityId=$("#commodity_id").val();
	  				 
	  				 $.ajax({
	  					 type:"POST", 
	  					 url:"/user/changeGoods?v="+Math.random(),
	  					 data:{
	  						 "goodsId":commdityId,
	  						 "num":num
	  					 },
	  					 dataType:"json",
	  					 success:function(data){
	  							// 铃声 
								var audio=document.createElement("audio");
						        audio.src='/public/lobster/video/dingding.mp3';
						        audio.play();
	  						 if(data.success){
	  							  //跳转到我的订单页面
	  							  xxy.popup("提示","兑换商品成功!","确认","取消");
	  							  
	  							  $('#xxy-popup-done').bind('click',function(){
	  									 window.location.href='depot.html';
	  							  });
	  							 
	  						 }else{
	  							 xxy.popup("提示",data.msg,"确认","取消"); 
	  							 
	  						 }
	  					 }
	  				 });
	  		  }	   
  	  	});
    }
}
   
    /*原有的方法  */
	


function success(){
    window.location.href = 'jiou.html';

 //    var depotId = $("#depotId").val();
 //    var goodsId = $("#goodsId").val();
	// window.location.href="/user/jiou?depotId=" + depotId
	// 			+ "&goodsId=" + goodsId;
}
//去提货
function gopickup(){
    window.location.href = 'pickup.html';
	// var depotId = $("#depotId").val();
	// window.location.href="/user/pickup?depotId="+depotId;
}

//判断不为空
function noempty(name) {
	var reg1 = /^\s*$/;
	//如果是空字符串
	if (reg1.test($(name).val())) {
		$(name).next("h4").html("输入不能为空!");
		return;
	}
	$(name).next("h4").html("");
	return  true;
}



function gohongbao(){
    window.location.href = 'openRedPack.html';

	// var depotId = $("#depotId").val();
 //    var goodsId = $("#goodsId").val();
	// window.location.href="/redpack/openRedPack?depotId=" + depotId
	// + "&goodsId=" + goodsId;
}

function　goPoint(){
	var depotId = $("#depotId").val();
    var goodsId = $("#goodsId").val();
	window.location.href="/point/toPoint?depotId=" + depotId
	+ "&goodsId=" + goodsId;
}



</script>
<script>
//初始化rem
function initRem(){
	rem=window.innerWidth/7.5 + 'px';
	document.documentElement.style.fontSize = rem;
}
initRem();
//监听页面变化
window.onresize=function(){  
	initRem();
}
window.setTimeout(function(){
	initRem();
},20);
</script>
</html>